package com.example.testrecorder.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.testrecorder.R;
import com.example.testrecorder.domain.User;
import com.example.testrecorder.utils.DateUtil;
import com.example.testrecorder.utils.Des3Util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yingyong Lao
 * 创建时间 2021/6/12 16:13
 * @version 1.0
 */
public class UserAdapter extends BaseAdapter {
    private List<User> list=new ArrayList<>();

    public UserAdapter(List<User> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        User user = list.get(position);
        ViewHolder viewHolder=null;
        if(convertView==null){
            convertView=LayoutInflater.from(parent.getContext()).inflate(R.layout.user_item,parent,false);
            viewHolder=new ViewHolder();
            viewHolder.idTv=convertView.findViewById(R.id.idTv);
            viewHolder.ageTv=convertView.findViewById(R.id.ageTv);
            viewHolder.emailTv=convertView.findViewById(R.id.emailTv);
            viewHolder.genderTv=convertView.findViewById(R.id.genderTv);
            viewHolder.passwordTv=convertView.findViewById(R.id.passwordTv);
            viewHolder.registerDateTv=convertView.findViewById(R.id.registerDateTv);
            viewHolder.telTv=convertView.findViewById(R.id.telTv);
            viewHolder.trueNameTv=convertView.findViewById(R.id.trueNameTv);
            viewHolder.usernameTv=convertView.findViewById(R.id.usernameTv);
            viewHolder.headPortraitTv=convertView.findViewById(R.id.headPortraitTv);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.idTv.setText(""+user.getId());
        viewHolder.ageTv.setText(""+user.getAge());
        viewHolder.emailTv.setText(user.getEmail());
        viewHolder.genderTv.setText(user.getGender());
        viewHolder.passwordTv.setText(Des3Util.decrypt("lyy",user.getPassword()));
        viewHolder.registerDateTv.setText(DateUtil.getFormatDateStr(user.getRegisterDate()));
        viewHolder.telTv.setText(user.getTel());
        viewHolder.trueNameTv.setText(user.getTrueName());
        viewHolder.usernameTv.setText(user.getUserName());
        viewHolder.headPortraitTv.setText(user.getHeadPortraitStr());
        return convertView;
    }
    static class ViewHolder{
        TextView idTv,usernameTv,passwordTv,trueNameTv,telTv,ageTv,genderTv,emailTv,registerDateTv,headPortraitTv;
    }
}
